package com.woniu.mall.controller;

import com.woniu.common.annotation.LoginUser;
import com.woniu.common.entity.PageData;
import com.woniu.common.entity.Result;
import com.woniu.mall.VO.HotProductVO;
import com.woniu.mall.VO.ProductDetailVO;
import com.woniu.mall.VO.ProductListVO;
import com.woniu.mall.pojo.MallProduct;
import com.woniu.mall.pojo.MallStore;
import com.woniu.mall.service.IMallOrderService;
import com.woniu.mall.service.IMallProductService;
import com.woniu.user.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 坤
 * @since 2023-05-22
 */
@RestController
@RequestMapping("/mallProduct")
@Api(tags = "商品管理")
public class MallProductController {
    @Autowired
    private IMallProductService productService;

    @ApiOperation("搜索商品")
    @PostMapping("/listSearch/{title}")
    public Result listSearch(@PathVariable String title) {
        List<ProductListVO> productListVOList = productService.listSearch(title);
        return Result.ok(productListVOList);
    }

    @ApiOperation("商品详情")
    @PostMapping("/detail/{pid}")
    public Result showDetail(@PathVariable Integer pid) {
        ProductDetailVO productDetailVO = productService.showDetail(pid);
        return Result.ok(productDetailVO);
    }

    @ApiOperation("根据商品id查询商家信息")
    @PostMapping("/getStore/{pid}")
    public Result getStore(@PathVariable Integer pid) {
        MallStore store = productService.getStore(pid);
        return Result.ok(store);
    }

    @ApiOperation("热门商品推荐")
    @PostMapping("/hotProduct/{num}")
    public Result hotProduct(@PathVariable Integer num) {
        List<HotProductVO> hotProducts = productService.hotProduct(num);
        return Result.ok(hotProducts);
    }

    @ApiOperation("获取分类下对应商品列表")
    @PostMapping("/category/{category}")
    public Result getByCategory(@PathVariable String category) {
        List<ProductListVO> productListVOList = productService.getByCategory(category);
        return Result.ok(productListVOList);
    }

    @ApiOperation("获取分类对应图标")
    @PostMapping("/getCategoryIcon/{category}")
    public Result getCategoryIcon(@PathVariable String category) {
        String categoryIcon = productService.getCategoryIcon(category);
        return Result.ok(categoryIcon);
    }

    @ApiOperation("充值比特币")
    @PostMapping("/recharge")
    public Result recharge(@LoginUser UserLoginVO userLoginVO, @RequestParam BigDecimal amount) {
        Object response = productService.recharge(userLoginVO, amount);
        return Result.ok(response);
    }

    @ApiOperation("添加库存")
    @PostMapping("/addStock/{pid}")
    public Result addStock(@PathVariable Integer pid) {
        Integer result = productService.addStock(pid);
        return Result.ok(result);
    }

    @ApiOperation("扣减库存")
    @PostMapping("/reduceStock/{pid}")
    public Result reduceStock(@PathVariable Integer pid) {
        Integer result = productService.reduceStock(pid);
        return Result.ok(result);
    }

    @ApiOperation("添加商品")
    @PostMapping("/addProduct")
    public Result addProduct(MallProduct product){
        Integer result = productService.addProduct(product);
        return Result.ok(result);
    }
    @ApiOperation("删除商品")
    @PostMapping("/deleteProduct")
    public Result deleteProduct(Integer pid){
        Integer result = productService.deleteProduct(pid);
        return Result.ok(result);
    }



}
